package cn.stylefeng.guns.core.common.entity;



import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.stylefeng.guns.core.common.exception.ApiExceptionEnum;
import com.fasterxml.jackson.annotation.JsonInclude;



/**    
* @Title: AppResponse.java 
* @Package com.shyl.framework.entity.app
* @Description: 基础响应信息
* @author:作者
* @date 2016年3月11日 下午3:26:55 
* @version V1.0    
* 
* 包含返回码code和返回信息msg还有返回对象
* 如果是列表用datas
* 单个对象用data
*/ 
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ApiResponse extends HashMap{
	private static final String LIST = "list";

	private static final String CODE = "code";
	private static final String MSG = "msg";


	public ApiResponse() {

	}

	public ApiResponse(String key, Object value) {
		this();
		this.put(key, value);
	}


	/**
	 * 请求成功
	 * 需要手动put返回数据
	 * @return
	 */
	public static ApiResponse success(){
		ApiResponse result = new ApiResponse();
		result.put(CODE,ApiExceptionEnum.SUCCESS.getCode());
		result.put(MSG,ApiExceptionEnum.SUCCESS.getMessage());
		return result;
	}

	/**
	 * 请求成功
	 * 放list map
	 * @return
	 */
	public static ApiResponse success(List<Map<String, Object>> list){
		ApiResponse result = new ApiResponse();
		result.put(CODE,ApiExceptionEnum.SUCCESS.getCode());
		result.put(MSG,ApiExceptionEnum.SUCCESS.getMessage());
		result.put(LIST,list);
		return result;
	}

	/**
	 * 请求失败
	 * @param e
	 * @return
	 */
	public static ApiResponse error(ApiExceptionEnum e){
		ApiResponse result = new ApiResponse();
		result.put(CODE,e.getCode());
		result.put(MSG,e.getMessage());
		return result;
	}

}
